home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / UNIX / C / C-STYLE / STYLE < prev    next >
Text File  |  1992-11-23  |  1KB  |  56 lines

  1. TMP1=/tmp/style1$$
  2. TMP2=/tmp/style2$$
  3. RESULTS=/tmp/stat$$
  4. LIB=.
  5. trap "rm -f $TMP1 $TMP2 $RESULTS; trap ''0; exit" 0 1 2 13 15
  6.  
  7. for i 
  8. do
  9.     echo; echo 'Style analysis of ' $i
  10.     if test -r $i
  11.     then        : --- count comment lines and total lines.
  12.  
  13.         awk -f $LIB/style.cnt.awk $i > $RESULTS
  14.             :
  15.             : --- replace tabs by spaces
  16.             : --- convert to lower case
  17.             : --- fix strings and comment delimiters
  18.             : --- remove comments
  19.             :
  20.         $LIB/style.detab < $i |\
  21.             tr "[A-Z]" "[a-z]" |\
  22.             sed -f $LIB/style.str.sed |\
  23.             sed -n -f $LIB/style.com.sed > $TMP1
  24.             :
  25.             : --- sort program words
  26.             :
  27.         tr -cs "a-z0-9_" "\012" < $TMP1 |\
  28.             sed -n '/^[a-z]/p' |\
  29.             sort -u > $TMP2
  30.             :
  31.             : --- find length of user identifiers.
  32.             :
  33.         comm -23 $TMP2 $LIB/style.dict |\
  34.             awk >> $RESULTS \
  35.                 '{totl += length}; \
  36.                   END {print "NL ";\
  37.                        if (NR) print (totl/NR); else print 0;\
  38.                        print "ID " NR }'
  39.             :
  40.             : --- count variety of reserved woeds
  41.             :
  42.         comm -12 $TMP2 $LIB/style.dict |\
  43.             (echo "RW" `wc -l`) >> $RESULTS
  44.             :
  45.             : --- produce remaining metrics
  46.             :
  47.         awk -f $LIB/style.met.awk $TMP1 >> $RESULTS
  48.             :
  49.             : --- and analyse
  50.             :
  51.         $LIB/style.stan < $RESULTS
  52.     else echo " Cannot read"; echo ""
  53.     fi
  54. done
  55.  
  56.